Haptic 5 Click
Haptic 5 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.
Click Library
- Author : Stefan Filipovic
- Date : Apr 2025.
- Type : PWM type
Software Support
Example Description
This example demonstrates the control of the Haptic 5 Click board. In I2C mode, the example toggles the haptic trigger pin periodically to generate vibration pulses. In PWM mode, it gradually increases and decreases the output duty cycle to modulate the vibration intensity, while toggling the direction when the duty reaches 0%.
Example Libraries
- MikroSDK.Board
- MikroSDK.Log
- Click.Haptic5
Example Key Functions
- haptic5_cfg_setup This function initializes Click configuration structure to initial values.
void haptic5_cfg_setup(haptic5_cfg_t *cfg)
Haptic 5 configuration object setup function.
Haptic 5 Click configuration object.
Definition haptic5.h:225
- haptic5_init This function initializes all necessary pins and peripherals used for this Click board.
err_t haptic5_init(haptic5_t *ctx, haptic5_cfg_t *cfg)
Haptic 5 initialization function.
Haptic 5 Click context object.
Definition haptic5.h:202
- haptic5_default_cfg This function executes a default configuration of Haptic 5 Click board.
err_t haptic5_default_cfg(haptic5_t *ctx)
Haptic 5 default configuration function.
- haptic5_set_duty_cycle This function sets the PWM duty cycle.
err_t haptic5_set_duty_cycle(haptic5_t *ctx, float duty_cycle)
Haptic 5 set duty cycle function.
- haptic5_toggle_dir This function toggles the state of the DIR pin.
void haptic5_toggle_dir(haptic5_t *ctx)
Haptic 5 toggle direction function.
Application Init
Initializes the logger and the Click board driver, and applies the default configuration.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define HAPTIC5_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition haptic5.h:186
@ HAPTIC5_ERROR
Definition haptic5.h:250
void application_init(void)
Definition main.c:35
Application Task
Depending on the selected communication interface (I2C or PWM), toggles the haptic trigger (I2C), or changes PWM duty cycle and direction (PWM).
{
#if ( HAPTIC5_DEFAULT_COM == HAPTIC5_COM_I2C )
log_printf( &logger, " Haptic state: Active\r\n\n" );
haptic5_set_trg_high ( &haptic5 );
Delay_ms ( 1000 );
log_printf( &logger, " Haptic state: Idle\r\n\n" );
haptic5_set_trg_low ( &haptic5 );
Delay_ms ( 1000 );
#else
static int8_t duty_cnt = 1;
static int8_t duty_inc = 1;
float duty = duty_cnt / 10.0;
log_printf( &logger, "> Duty: %d%%\r\n", ( uint16_t )( duty_cnt * 10 ) );
Delay_ms ( 500 );
if ( 10 == duty_cnt )
{
duty_inc = -1;
}
else if ( 0 == duty_cnt )
{
duty_inc = 1;
}
duty_cnt += duty_inc;
#endif
}
void application_task(void)
Definition main.c:71
Note
The mode is selected via the HAPTIC5_DEFAULT_COM macro. Ensure proper configuration and wiring based on the selected mode before running the example.
Application Output
This Click board can be interfaced and monitored in two ways:
- Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
- UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.
Additional Notes and Information
The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.